# coding=utf-8

import os.path
import subprocess
import uuid


def get_snapshot(local_path):
    name = "{}.png".format(uuid.uuid4())
    screen_cap_cmd = "adb shell screencap -p /sdcard/{}".format(name)
    subprocess.Popen(screen_cap_cmd).wait()
    upload_cmd = "adb pull /sdcard/{name} {path}".format(name=name, path=local_path)
    subprocess.Popen(upload_cmd).wait()
    clean_cmd = "adb shell rm /sdcard/{}".format(name)
    subprocess.Popen(clean_cmd).wait()


if __name__ == "__main__":
    get_snapshot(os.path.join(os.path.abspath("."), '..','screenshot', 'a.png'))
